package java7_26;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.omg.CORBA.portable.InputStream;

public class Filezuoye4 {
	public static void main(String[] args) throws Exception {
		File src=new File("F://jieshuxitong");
		File dec=new File("copy");
		copy(src,dec);
	}

	private static void copy(File src, File dec) throws Exception {
		 if(src.isDirectory()){
			 if(!dec.exists()){
				 dec.mkdirs();
			 }
			 File[] listFiles = src.listFiles();
			 for(File file:listFiles){
				 copy(file,new File(dec,file.getName()));
			 }
		 }else{
			 FileInputStream fileInputStream = new FileInputStream(src);
			 FileOutputStream fileOutputStream = new FileOutputStream(dec);
			 byte[] b=new byte[1024];
			 int len=0;
			 while((len=fileInputStream.read(b))!=-1){
				 fileOutputStream.write(b);
			 }
			 fileInputStream.close();
			 fileOutputStream.close();
		 }
	}
}
